package serviceset4;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import serviceset4.feign.ServiceSet3;
import serviceset4.restTemplate.ServiceSet3Proxy;

import java.security.Principal;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
public class SampleApi2Controller {

    @Autowired
    private ServiceSet3 serviceSet3;

    @Autowired
    private ServiceSet3Proxy serviceSet3Proxy;

    @GetMapping(value = "/sampleApi2")
    public Map index(@RequestParam(required = false) String dependency, Principal principal) {
        Map result = new LinkedHashMap();

        result.put("provider", "sampleApi3@serviceSet3");
        result.put("dependency", dependency);
        result.put("principal", principal);

        if("restTemplate".equals(dependency)) {
            result.put("consumption", serviceSet3Proxy.sampleApi3(dependency));
        } else if("feign".equals(dependency)) {
            result.put("consumption", serviceSet3.sampleApi3(dependency));
        } else {
            result.put("consumption", serviceSet3Proxy.sampleApi3(dependency));
        }

        return result;
    }
}
